<?php

class Product_model extends CI_Model 
{
    function __construct()
    {
        parent::__construct();
    }

    function findAllCategories()
    {
    	$this->db->select('*');
		$this->db->from('ProdottiCategorie');

		$this->db->order_by("nome", "asc");

		$query = $this->db->get();

		return $query->result(); 
    }

    function saveCategory($category)
    {
        $this->db->insert('ProdottiCategorie', $category); 
    }

    function updateCategory($idCategoria, $category)
    {
        $this->db->where('id', $idCategoria);
        $this->db->update('ProdottiCategorie', $category); 
    }

    function deleteCategory($idCategoria)
    {
        $this->db->where('id', $idCategoria);
        $this->db->delete('ProdottiCategorie'); 
    }

    function getCategory($idCategoria)
    {
        $this->db->select('*');
        $this->db->from('ProdottiCategorie');
        $this->db->where('id',$idCategoria);

        $query = $this->db->get();

        return $query->row(); 
    }

    function getProducts($idCategoria)
    {
        $this->db->select('*');
        $this->db->where('idCategoria',$idCategoria);
        $this->db->from('Prodotti');

        $this->db->order_by("nome", "asc");

        $query = $this->db->get();

        return $query->result(); 
    }

    function saveProduct($product)
    {
        $this->db->insert('Prodotti',$product);
    }

    function updateProduct($idProduct, $product)
    {
        $this->db->where('id', $idProduct);
        $this->db->update('Prodotti', $product); 
    }

    function deleteProduct($idProduct)
    {
        $this->db->where('id', $idProduct);
        $this->db->delete('Prodotti'); 
    }
}

?>